﻿using System;
using System.Net;
using SCG.General;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //Freighters
    public class Freighter : ResourceStarShip
    {
        //constructor
        public Freighter(SVGame game, Player owner, int engines, int cargoBays, StarSystem origin)
            : base(game, owner, engines, cargoBays, origin)
        {
        }

        //Starship name
        public override string Name
        {
            get
            {
                return "Freighter";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "Freighters can transport Resources between friendly StarSystems and BattleStations.  Each Freighter has a Cargo rating that determines how many Resources it can hold.  Each Cargo Bay can carry 10 Resources.  So, a Freighter with 5 Cargo Bays could transport 50 Resources.";
            }
        }

        //Starship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.Freighter;
            }
        }

        //How much freight can a ship hold?
        public int Capacity
        {
            get
            {
                return Value * 10;
            }
        }

        //How much capacity is free?
        public int FreeCapacity
        {
            get
            {
                return Capacity - ResourcesInt;
            }
        }

        //Game piece stats mark
        public override string PrimarySystemMark
        {
            get
            {
                if (!DiscoveredByCurrentPlayer)
                    return "";
                else
                {
                    string s = "C" + Capacity;
                    if (ResourcesInt > 0)
                        s += " R" + ResourcesInt;
                    return s;
                }
            }
        }

        //additional order types
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.Unload:
                    return Resources > 0;
                case OrderType.Transport:
                    return true;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }

        //reduce cargo when damaged
        protected internal override void ProcessDamage(int damage, bool canDamageEngines)
        {
            base.ProcessDamage(damage, canDamageEngines);
            if (Resources > Capacity)
            {
                Resources = Capacity;
                Game.SubmitStateChange(StateChange.SetShipResources, this, Resources);
            }
        }
    }
}
